/*
 * ProjectTreeCellRenderer.java
 * 
 * last update: 14.01.2010 by Stefan Saru
 * 
 * author:	Felix(felix@ulise.cs.pub.ro)
 *
 * Obs: N/A
 */

package ide;


import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.text.*;
import javax.swing.tree.*;
import javax.swing.undo.*;
import javax.swing.text.html.*;
import java.awt.Component;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

public class ProjectTreeCellRenderer extends JLabel implements TreeCellRenderer
{
	/** Whether or not the item that was last configured is selected. */
	protected boolean            selected;

	/**
	 * This is messaged from JTree whenever it needs to get the size
	 * of the component or it wants to draw it.
	 * This attempts to set the icon based on user object type
	 * 
	 */
	public Component getTreeCellRendererComponent(JTree tree, Object value,
			boolean selected, boolean expanded,
			boolean leaf, int row,
			boolean hasFocus) {

		Font font;
		String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus);

		/* Set the text. */
		ProjectTreeNode userObject = (ProjectTreeNode)((DefaultMutableTreeNode)value).getUserObject();
		String nodeName = userObject.toString();
		if (userObject.type == ProjectTreeNode.FILETYPE)
			nodeName =
				nodeName.substring(nodeName.lastIndexOf(java.io.File.separatorChar) + 1,
						nodeName.length());
		//if file, display only name (not the absolute path)
		setText(nodeName);
		/* Tooltips used by the tree. */
		setToolTipText(userObject.getFQN());

		/* Set the image. */
		setIcon(userObject.getIcon());

		if(hasFocus)
			setForeground(Color.blue);
		else
			setForeground(Color.black);

		/* Update the selected flag for the next paint. */
		this.selected = selected;
		return this;
	}
}
